<div class="tar mt10">
    <#if shiro.hasPermission("sys:role:insert")>
        <a class="layui-btn layui-btn-normal layui-btn-small" href="role/edit">+添加</a>
    </#if>
</div>
<div class="table-list">
    <table class="layui-table layui-list-table">
        <thead>
        <tr>
            <th>名称</th>
            <th>状态</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <#list data as d>
            <tr>
                <td class="layui-table-first"><i class="layui-table-hd">名称</i><span
                        class="layui-table-bd">${d.name}</span></td>
                <td><i class="layui-table-hd">状态</i><span class="layui-table-bd">${d.statusText}</span></td>
                <td><i class="layui-table-hd">创建时间</i><span class="layui-table-bd">${d.createtime?string("yyyy-MM-dd HH:mm:ss")}</span>
                </td>
                <td>
                    <#if shiro.hasPermission("sys:role:update")>
                        <button class="layui-btn layui-btn-warm layui-btn-small"
                                onclick="location.href='/administrate/role/edit?id=${d.id}'">修改
                        </button>
                    </#if>
                    <#if shiro.hasPermission("sys:role:delete")>
                        <button class="layui-btn layui-btn-danger layui-btn-small btn_delete" data-id="${d.id}">删除
                        </button>
                    </#if>
                </td>
            </tr>
        </#list>
        </tbody>
    </table>
</div>
<!-- 分页 -->
<div id="pages" class="tac"></div>
<#macro script>
    <script>
        layui.use(['jquery', 'laypage'], function () {
            var $ = layui.jquery, laypage = layui.laypage;
            laypage.render({
                elem: 'pages'
                , layout: ['prev', 'page', 'next', 'count']
                , count: ${dataCount}
                , limit: ${pageSize}
                , curr: ${pageNo}
                , groups: 2
                , jump: function (obj, first) {
                    if (!first) {
                        reload(obj.curr)
                    }
                }
            });
            $(function () {
                $(".btn_delete").on("click", function () {
                    var id = $(this).data("id");
                    layer.confirm('将删除所有有关数据,是否继续?', {icon: 7, title: '警告', btn: ['是', '否']}, function () {
                        $.ajax({
                            type: "POST",
                            url: "/administrate/role/delete",
                            data: {id: id},
                            async: false,
                            dataType: "json",
                            success: function (result) {
                                if (result.code == 200) {
                                    layer.msg(result.msg);
                                    location.href = location.href;
                                }
                                else {
                                    layer.msg(result.msg);
                                }
                            }
                        });
                    });
                });
            });
            function reload(currPage) {
                location.href = window.location.pathname + "?pageNo=" + currPage;
            }
        });
    </script>
</#macro>